﻿using LoveNote.Application.Share.Login;
using LoveNote.Database.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using TookKit.Mvvm.Attributes;
using TookKit.Mvvm.Bindings;
using TookKit.Mvvm.Enums;

namespace LoveNote.Application.Setting.ViewModels
{
    [DependencyInjection(Lifetime.Singleton)]
    internal class SettingViewModel : ObservableObject
    {
        public ICommand SaveCurrentUserCommand { get; }

        public ISession Session { get; }
        private IUserRepository UserRepository { get; }
        public SettingViewModel(ISession session, IUserRepository userRepository)
        {
            Session = session;
            UserRepository = userRepository;
            SaveCurrentUserCommand = new RelayCommand(OnSaveCurrentUserCommand);
        }

        private void OnSaveCurrentUserCommand()
        {
            if (!string.IsNullOrEmpty(Session.CurrentUser.OldPassword))
            {
                if(Session.CurrentUser.OldPassword == Session.CurrentUser.Password)
                {
                    Session.CurrentUser.Password = Session.CurrentUser.NewPassword;
                }               
            }

            UserRepository.Update(Session.CurrentUser);
        }
    }
}
